package com.example.myapplication.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import android.content.Intent;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;

import com.example.myapplication.Fragment.CommentVideoFragment;
import com.example.myapplication.Fragment.VideoPlayDetailFragment;
import com.example.myapplication.R;
import com.example.myapplication.adapter.viewPagerAdapter.VideoPlayAdapter;
import com.example.myapplication.entity.RecommendVideo;
import com.example.myapplication.tools.BarTransparent;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;
import java.util.List;

public class VideoPlayActivity extends AppCompatActivity {
    private VideoView videoView;
    private TabLayout tab_layout;
    private ViewPager view_pager;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video_play);
        BarTransparent.makeStatusBarTransparent(this);
        BarTransparent.setAndroidNativeLightStatusBar(this,true);
        videoView = findViewById(R.id.videoView);
        view_pager = findViewById(R.id.view_pager);
        tab_layout = findViewById(R.id.tab_layout);
        Intent intent = getIntent();
        Bundle bundle = intent.getExtras();
        RecommendVideo.DatasBean datasBean = (RecommendVideo.DatasBean) bundle.getSerializable("video");
        List<Fragment> fragmentList = new ArrayList<>();
        fragmentList.add(new VideoPlayDetailFragment().newInstance(bundle));
        fragmentList.add(new CommentVideoFragment().newInstance(bundle));
        VideoPlayAdapter adapter = new VideoPlayAdapter(getSupportFragmentManager(),fragmentList);
        view_pager.setAdapter(adapter);
        tab_layout.setupWithViewPager(view_pager);
        initView(datasBean);

    }
    private void initView(RecommendVideo.DatasBean datasBean) {
        String url = datasBean.getData().getUrlInfo().getUrl();
        MediaController mediaController = new MediaController(this);
        videoView.setVideoPath(url);
        videoView.setMediaController(mediaController);
        videoView.requestFocus();
        videoView.start();
    }
}